<?php

namespace app\api\controller;

use think\Db;
use app\common\controller\Api;
use app\admin\model\Project;



class Projectapi extends Api
{

    protected $userId;

    /**
     * 责任项目
     */
    public function projectlist()
    {
        $params = $this->request->param();

        $page = $params['page'];
        $pageCount = $params['pageCount'];
        $project = new Project();
        $info = $project -> getInfo(null,$this->userId,null,null,"status asc, weigh desc,id desc",$page,$pageCount );
        //总数
        $total = Project::where(['user_id'=>$this->userId])->count();
        $result['total'] = $total;
        $result['info'] = $info;
        $result['pageTotal'] = count($info);
        $this->success('请求成功!!!',$result);
    }



    /**
     * 完成责任项目
     */
    public function completeproject()
    {
        $params = $this->request->param();
        $id = $params['id'];
        $flag = Db::table('zc_project')->where('id', $id)->update(['status' => '1']);
        if($flag == 1){
            $this->success('成功!!!');
        }else{
            $this->error('请求失败!!!');
        }
    }

    /**
     * 未完成项目数量
     */
    public function projectnum(){

        $project = new Project();
        $info = $project -> getInfo(null,$this->userId,null,"0","weigh desc,id desc",null,null );
        //总数
        $total = Project::where(['user_id'=>$this->userId,'status'=>"0"])->count();
        $result['total'] = $total;
        $this->success('请求成功!!!',$result);
    }

}
